Skip to content

fix(contracts): add stream_count view fn and fix resume_stream status… - #988

Open
Anthony-19 wants to merge 4 commits into
LabsCrypt:mainfrom
Anthony-19:anthony_flowfi
Open

fix(contracts): add stream_count view fn and fix resume_stream status…#988
Anthony-19 wants to merge 4 commits into
LabsCrypt:mainfrom
Anthony-19:anthony_flowfi

Conversation

@Anthony-19

Copy link
Copy Markdown
Contributor

… guard

Closes #421 — stream_count() -> u64

  • Add stream_count() read-only function that returns the global StreamCounter value (monotonically increasing, equals the highest stream ID ever issued, never decrements on cancel/complete).
  • Returns 0 on a freshly-deployed contract with no streams.
  • Add TypeScript binding fetchStreamCount() in frontend/src/lib/soroban.ts that simulates the view call without wallet auth.
  • Unit tests: stream_count_returns_zero_on_fresh_contract, stream_count_increments_by_one_per_create, stream_count_is_not_decremented_by_cancel, stream_count_matches_last_stream_id.

Closes #787 — resume_stream status guard

  • resume_stream now checks stream.status == Paused (not just stream.paused), so a stream cancelled while paused (status=Cancelled, paused=true) correctly returns StreamInactive instead of being resurrected to Active.
  • cancel_stream now explicitly clears stream.paused = false and stream.paused_at = None when settling a cancellation, ensuring no stale pause state survives into the Cancelled record.
  • Unit tests: resume_after_cancel_while_paused_returns_stream_inactive, cancel_while_paused_clears_pause_fields, cancel_normal_stream_also_clears_pause_fields.

Description

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test addition or update

Related Issues

Closes #

Changes Made

Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

Test Steps

Breaking Changes

Breaking Changes:

Migration Guide:

Screenshots/Demo

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published
  • I have checked for breaking changes and documented them if applicable

Additional Notes

… guard

Closes LabsCrypt#421 — stream_count() -> u64
- Add stream_count() read-only function that returns the global
  StreamCounter value (monotonically increasing, equals the highest
  stream ID ever issued, never decrements on cancel/complete).
- Returns 0 on a freshly-deployed contract with no streams.
- Add TypeScript binding fetchStreamCount() in frontend/src/lib/soroban.ts
  that simulates the view call without wallet auth.
- Unit tests: stream_count_returns_zero_on_fresh_contract,
  stream_count_increments_by_one_per_create,
  stream_count_is_not_decremented_by_cancel,
  stream_count_matches_last_stream_id.

Closes LabsCrypt#787 — resume_stream status guard
- resume_stream now checks stream.status == Paused (not just stream.paused),
  so a stream cancelled while paused (status=Cancelled, paused=true) correctly
  returns StreamInactive instead of being resurrected to Active.
- cancel_stream now explicitly clears stream.paused = false and
  stream.paused_at = None when settling a cancellation, ensuring no stale
  pause state survives into the Cancelled record.
- Unit tests: resume_after_cancel_while_paused_returns_stream_inactive,
  cancel_while_paused_clears_pause_fields,
  cancel_normal_stream_also_clears_pause_fields.
…tream

The pause state clearance (paused=false, paused_at=None) was placed after
the CEI-refactored save_stream call, putting it inside the interactions block
where token_client/contract_address are in scope but stream state mutations
should not happen. Move the two lines up into the effects block, before
save_stream, consistent with the existing is_active/status/last_update_time
assignments.
# Conflicts:
#	contracts/stream_contract/src/lib.rs

@ogazboiz ogazboiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two genuinely valuable things in here: stream_count still does not exist on main, and the cancelled-while-paused hole is real (cancel_stream never clears paused, and resume_stream only checks !stream.paused, so a cancelled stream can be resumed to Active). to land it:

  1. fix the file encoding: the diff mojibakes every UTF-8 character in lib.rs (em dashes become garbage), which corrupts docs file-wide. save as UTF-8 so the diff touches only real lines.
  2. rebase onto main: resume_stream was rewritten there, so re-apply just the Paused-status guard, and clear paused in cancel_stream too.
  3. drop or justify the frontend/soroban.ts change.

if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants